package br.com.massai.model.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.envers.Audited;

import br.com.massai.view.enums.StatusEnum;

@Entity
@Audited
@Table(name = "DEPARTMENT")
@NamedQueries({
	@NamedQuery(name = "Department.find", query = "SELECT d FROM Department d"),
	@NamedQuery(name = "Department.duplicate", query = "SELECT d FROM Department d WHERE d.code =:code")
})
public class Department extends GenericEntity {

	private static final long serialVersionUID = 1009889013048421373L;

	@Id
	@SequenceGenerator(name = "seqDepartment", sequenceName = "seq_department", allocationSize = 1)
	@GeneratedValue(generator = "seqDepartment", strategy = GenerationType.SEQUENCE)
	private Long id;
	
	@Column(name = "CODE", length = 14, columnDefinition = "VARCHAR(14)")
	private String code;
	
	@Column(name = "CODE_SIENGE", columnDefinition = "NUMERIC(9,0)")
	private Long codeSienge;
	
	@Column(name = "NAME_DEPARTMENT", length = 150, columnDefinition = "VARCHAR(150)")
	private String nameDepartment;
	
	@Enumerated(EnumType.STRING)
	@Column(name = "STATUS", columnDefinition = "CHAR(1)")
	private StatusEnum status;
	
	@ManyToOne(optional = true, fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "PRODUCTION_GROUP_ID", referencedColumnName = "ID")
	private ProductionGroup productionGroup;
	
	//TODO add relationship with LIST USERs [COLLABORATORS]

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getNameDepartment() {
		return nameDepartment;
	}

	public void setNameDepartment(String nameDepartment) {
		this.nameDepartment = nameDepartment;
	}

	public Long getCodeSienge() {
		return codeSienge;
	}

	public void setCodeSienge(Long codeSienge) {
		this.codeSienge = codeSienge;
	}

	public ProductionGroup getProductionGroup() {
		return productionGroup;
	}

	public void setProductionGroup(ProductionGroup productionGroup) {
		this.productionGroup = productionGroup;
	}

	public StatusEnum getStatus() {
		return status;
	}

	public void setStatus(StatusEnum status) {
		this.status = status;
	}
	
}
